package search;

public class BinSearch {
    public static int BinarySearch(int massiv[], int x) {
        int n = massiv.length;
        int end = n - 1, start = 0;
        int count = 0;
        boolean flag = true;
        boolean found = false;
        while (!found && count < n) {
            int i = start + (end - start) / 2;
            if (massiv[i] == x) {
                found = true;
                System.out.println("You are awesome: " + (i + 1));
            } else if (massiv[i] < x) {
                start = i;
                count++;
            } else if (massiv[i] > x) {
                end = i;
                count++;
            }
        }

        if (count != n) {
            return count;
        } else {
            return -1;
        }

    }
}